package com.ruoyi.project.hcy.administrations.service.Impl;

import com.ruoyi.project.hcy.administrations.domain.Approve;
import com.ruoyi.project.hcy.administrations.domain.Posting;
import com.ruoyi.project.hcy.administrations.mapper.ApproveMapper;
import com.ruoyi.project.hcy.administrations.mapper.PostingMapper;
import com.ruoyi.project.hcy.administrations.service.IDimissionService;
import com.ruoyi.project.hcy.administrations.service.IPostingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName PostingServiceImpl
 * @Author 金刚芭比
 * @Date 2020/9/17 10:54
 * @Version 1.0
 */
@Service
public class PostingServiceImpl implements IPostingService {

    @Autowired
    private PostingMapper postingMapper;

    @Autowired
    private ApproveMapper approveMapper;

    @Override
    public List<Posting> selectPostingAll(String postingStatus) {
        return postingMapper.selectPostingAll(postingStatus);
    }

    @Override
    public int insertPosting(Posting posting) {
        //添加默认值
        posting.setPostingType("职位调整申请");
        posting.setPostingStatus("待审批..");
        int insert = postingMapper.insertPosting(posting);
        if (insert>0){
            Approve approve = new Approve();
            approve.setApproveName(posting.getPostingName());
            approve.setApproveTitle(posting.getPostingName()+"申请职位调整,原职位"+posting.getPostingOldjob()+"-->新职位:"+posting.getPostingNewjob());
            approve.setApproveStatus(posting.getPostingStatus());
            approve.setApproveType(posting.getPostingType());
            approveMapper.insertApprove(approve);
        }
        return insert;
    }

    @Override
    public int updatePostingStatus(Posting posting) {
        return postingMapper.updatePostingStatus(posting);
    }

    @Override
    public Posting selectPostingByName(String postingName) {
        return postingMapper.selectPostingByName(postingName);
    }
}
